<template>
  <div class="mainDiv">
    <div class="content">
      <div style="padding: 0 10px">
        <mt-swipe :auto="4000" id="banner" style="height: 100px">
          <mt-swipe-item v-for="item in banners">
            <img class="banner" v-bind:src="item" alt="">
          </mt-swipe-item>
        </mt-swipe>
      </div>
      <div class="icons">
        <router-link  v-for="cell in cells" :to="cell.url" class="iconBlock">
          <img v-bind:src="cell.icon" width="46" height="46" />
          <div class="mt5">{{cell.title}}</div>
        </router-link>
      </div>
       <div class="line"></div>
      <mt-cell class=" border-bot" title="高考资讯" style="font-weight: bold"></mt-cell>
      <div class="">
        <mt-cell class=" border-bot h60" v-for="news in newsList" :to="'/news/news/'+news.id" >
          <div slot="title">
            <div class="col-8" style="display: flex;align-items: center;float: left;height: 60px">
              <div class="col-tit" style="height: auto;margin-bottom: 0" >{{news.title}}</div>
            </div>
            <div class="col-4 col-date" style="line-height: 60px">
              {{news.time|formatDate}}
            </div>
          </div>
        </mt-cell>
      </div>
    </div>
  </div> 
</template>

<script>
    import {formatDate} from '@/assets/commonUtil.js'
    export default {
        name: "MainPage",
      data(){
        return {
          newsList:[],
          banners:
          [require("../assets/ad/banner.png")],
          cells:[
            {title:"智能志愿",value:"让选择更简单",icon:require("../assets/cells/智能志愿.png"),url:"/student/overview"},
             {title:"高校之窗",value:"名校风采尽在于此",icon:require("../assets/cells/高校.png"),url:"/college/collegeList"},
            {title:"我的志愿",value:"梦想看今朝",icon:require("../assets/cells/奖章.png"),url:"/collections"},
            {title:"专业探索",value:"选专业就靠它",icon:require("../assets/cells/探索.png"),url:"/college/majorTypes"}]//vip功能
        }
      },
      filters:{
        formatDate(time) {
          var date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd');
        }
      },
      created:function(){
          var vm = this;
          this.$http.get('/wx/latestNews').then(function (response) {
            console.log(response);
            vm.newsList = response.data.data;
          })
      },
      mounted:function(){
        var clientWidth = document.documentElement.clientWidth || window.innerWidth;
        document.querySelector("#banner").style.height = (clientWidth<620?(clientWidth*0.4):236) + 'px';
      }
    }
</script>
<style scoped>
  .mint-swipe img.banner{
    width: 100%;
    height: 100%;
    border-radius: 5px;
  }
  .mint-swipe img.newsIcon{
    width:24px;
    height: 24px;
    vertical-align: top;
    margin:0 15px;
  }
  .icons{
    padding: 15px 10px;
    display: flex;
    justify-content:space-between
  }
  .icons div{
    color: black;
    font-size: 14px;
  }
 .iconBlock{
       text-align: center;
 }

</style>
